Skip to content

[lua] Add support for lua 5.5#12867

Open
tobil4sk wants to merge 8 commits intoHaxeFoundation:developmentfrom
tobil4sk:feature/lua-5.5
Open

[lua] Add support for lua 5.5#12867
tobil4sk wants to merge 8 commits intoHaxeFoundation:developmentfrom
tobil4sk:feature/lua-5.5

Conversation

@tobil4sk
Copy link
Copy Markdown
Member

@jdonaldson
Copy link
Copy Markdown
Member

jdonaldson commented Mar 27, 2026

A few things I noticed:

  1. luautf8 bump 0.1.6-10.2.1-1 — We've had issues in the past with newer luautf8 having stricter UTF-8 validation that broke edge case tests. Is this bump required for 5.5 compat, or incidental?

  2. Other removed math functionsmath.cosh, math.sinh, math.tanh, and math.log10 were removed in Lua 5.3 but the extern in lua/Math.hx still exposes them unconditionally. Pre-existing issue, but since this PR is tackling version compat it might be worth adding #if !(lua_ver >= 5.3) guards on those too.

  3. atan signature change is unconditional — The extern changes to atan(y:Float, ?x:Float) for all Lua versions, but on 5.1/5.2 math.atan only takes one arg — the ?x would be silently ignored. The docstring mentions this, which is good, but it could be a subtle footgun for anyone calling lua.Math.atan(y, x) on older versions and getting wrong results without error.

Also — what's the plan for the hx-lua-simdjson dependency? Is that close to being merged, or does this PR need to wait on it?

@tobil4sk
Copy link
Copy Markdown
Member Author

  1. This is explained in the commit message:

Lua 5.5 requires 0.1.7+, but 0.1.7 to 0.2.0 have a bug with invalid
arguments to utf8.char. 0.2.1 gives 5.5 support and fixes the argument
issue.

This is what gives 5.5 compat but causes a crash in edge cases: starwing/luautf8@38b1541, and this is the bug fix that fixes the crash: starwing/luautf8#60

  1. These are actually in the same situation as atan2: they were deprecated in lua 5.3 but it looks like they still exist in 5.3 and 5.4, and are removed properly in 5.5. So I guess that makes sense to handle here

  2. Currently we need atan and atan2 to have compatible signatures for version agnostic builds:
    https://github.com/tobil4sk/haxec/blob/e13af455497518c8afe5f818d01c09a1c83059b2/std/lua/_std/Math.hx#L101
    I'll try to see if we can change the definition for lua_ver<=5.2. If no lua_ver is set we probably should still show both arguments? Not sure what the best solution is there.

The hx-lua-simdjson PR should be ready to merge

@jdonaldson
Copy link
Copy Markdown
Member

Tested luautf8 0.2.1 locally — you're right, the bump is safe. Confirmed that 0.1.7 crashes on utf8.char(-1) (C assertion failure) and 0.2.1 fixes it cleanly. The 0.2.0 width() API break doesn't affect us since Haxe never calls those functions. Edge case validation (surrogates, overlong sequences, beyond-max codepoints) all behaves identically to 0.1.5.

Good to know about the cosh/sinh/tanh/log10 situation — makes sense to handle them here since they follow the same deprecation→removal pattern as atan2.

@tobil4sk
Copy link
Copy Markdown
Member Author

tobil4sk commented Apr 9, 2026

I handled the other deprecations as suggested. I also hid the 2nd atan argument when explicitly targeting 5.1/5.2 and luajit, though it is still exposed for untargeted builds.

In lua 5.3, math.atan2 was deprecated in favour of a two argument
version of math.atan. In 5.5, math.atan2 has finally been removed so if
atan2 is missing at runtime we should use atan instead.

If 5.3 is targetted explicitly, we can assume that atan will take two
arguments so we don't have to do a runtime check.
Lua 5.5 requires 0.1.7+, but 0.1.7 to 0.2.0 have a bug with invalid
arguments to utf8.char. 0.2.1 gives 5.5 support and fixes the argument
issue.
These were deprecated in 5.3 but still exist even in lua 5.5.
The exponent operator is available in all supported lua versions so we
can use that instead. math.pow is deprecated in lua 5.3 and removed in
lua 5.5.
When targetting these versions we know that atan2 is available so we can
use it directly.
@jdonaldson
Copy link
Copy Markdown
Member

Is this safe to merge?

@tobil4sk
Copy link
Copy Markdown
Member Author

I think it should be, if the version handling looks good to you now?

Copy link
Copy Markdown
Member

@jdonaldson jdonaldson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version handling looks good. Verified against local Lua 5.5:

  • atan2, cosh, sinh, tanh, pow, log10 — confirmed absent in 5.5, correctly guarded
  • frexp, ldexp — confirmed still present in 5.5, correctly just deprecated
  • atan signature split and runtime ?? fallback for unversioned builds is clean
  • pow^ operator is the right move (works everywhere)

LGTM.

@jdonaldson
Copy link
Copy Markdown
Member

@Simn do you want to give this one final sniff and do the honors? I believe it's an improvement for handling runtime variants across the Lua target versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants